package org.jeecg.modules.workflow.convert.task;

import org.flowable.engine.history.HistoricActivityInstance;
import org.jeecg.common.workflow.vo.task.activity.BpmActivityRespVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BpmActivityConvertImpl implements BpmActivityConvert {

    @Override
    public List<BpmActivityRespVO> convertList(List<HistoricActivityInstance> list) {
        if ( list == null ) {
            return null;
        }

        List<BpmActivityRespVO> list1 = new ArrayList<BpmActivityRespVO>( list.size() );
        for ( HistoricActivityInstance historicActivityInstance : list ) {
            if("MI_END".equals(historicActivityInstance.getDeleteReason())){
                continue;
            }
            list1.add( convert( historicActivityInstance ) );
        }

        return list1;
    }

    @Override
    public BpmActivityRespVO convert(HistoricActivityInstance bean) {
        if ( bean == null ) {
            return null;
        }

        BpmActivityRespVO bpmActivityRespVO = new BpmActivityRespVO();

        bpmActivityRespVO.setKey( bean.getActivityId() );
        bpmActivityRespVO.setType( bean.getActivityType() );
        bpmActivityRespVO.setStartTime( bean.getStartTime() );
        bpmActivityRespVO.setEndTime( bean.getEndTime() );
        bpmActivityRespVO.setTaskId( bean.getTaskId() );

        return bpmActivityRespVO;
    }
}
